//
//  BaseViewController.swift
//  SwiftWB
//
//  Created by 远成物流 on 2017/6/23.
//
//

import UIKit

class BaseViewController: UITableViewController {
    
    ///懒加载
    lazy var vistorView = VistorView.vistowView()
    
    var isLogin : Bool = UserAccoutViewModel.shareInstance.isLogin
    
    override func loadView() {
        ///根据登录状态显示访客视图或主视图
        isLogin ? super.loadView() : setVistorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        ///设置导航栏
        setupNavigation()
    }
}

///Mark - UI
extension BaseViewController{
    
    func setVistorView() {
        view = vistorView
        
        vistorView.registerBtn.addTarget(self, action: #selector(registerAction), for: .touchUpInside)
        vistorView.loginBtn.addTarget(self, action: #selector(loginAction), for: .touchUpInside)
    }
    
    func setupNavigation() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(registerAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(loginAction))
    }
}

///Mark - 点击事件监听
extension BaseViewController{
    func registerAction() {
        
    }
    
    func loginAction() {
        let oauthVC = UINavigationController(rootViewController: OauthController())
        present(oauthVC, animated: true, completion: nil)
    }
}
